#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1505;
int n,head[N],nxt[N],w[N],fa[N],dep[N];
inline int dis(int x,int y){
	int sum=0;cerr<<x<<' '<<y<<' ';
	while(x!=y){
		if(dep[x]>=dep[y]) sum+=w[x],x=fa[x];
		else sum+=w[y],y=fa[y];
	}
	cerr<<sum<<'\n';
	return sum;
}
void dfs(int p){
	for(int v=head[p];v;v=nxt[v]){
		dep[v]=dep[p]+1; 
		dfs(v);
	}
}
int f[1<<12][12],p[N],cnt;
signed main(){
//	freopen("trip.in","r",stdin);
//	freopen("trip.out","w",stdout);
	cin>>n;
	for(int i=2;i<=n;++i){
		cin>>fa[i]>>w[i];
		nxt[i]=head[fa[i]],head[fa[i]]=i;
	
	}
	dfs(1);
	for(int i=1;i<=n;++i) if(!nxt[head[i]]) p[cnt++]=i;
	memset(f,0x3f,sizeof(f));
	for(int i=0;i<cnt;++i) f[1<<i][i]=0;
	for(int z=1;z<(1<<cnt);++z)
	for(int i=0;i<cnt;++i) if(f[z][i]<1e9&&((z>>i)&1))
	for(int k=0;k<cnt;++k) if(!((z>>k)&1)){
		f[z|(1<<k)][k]=min(f[z|(1<<k)][k],max(f[z][i],dis(p[i],p[k])));
	}
	int ans=1e9;
	for(int i=0;i<cnt;++i) ans=min(ans,f[(1<<cnt)-1][i]);
	cout<<ans;
	return 0;
}


